﻿@model Models.Users

@{
    Layout = null;
    ViewData["Title"] = "修改二级密码";
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>@ViewData["Title"]</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">@ViewData["Title"]</div>
                    <div class="layui-card-body" pad15>
                        <div class="layui-form" action="" lay-filter="">
                            @if (Model != null && (Model.SecondaryPwd + "").Length > 0) {
                                <div class="layui-form-item">
                                    <label class="layui-form-label">旧密码</label>
                                    <div class="layui-input-inline">
                                        <input type="password" maxlength="18" name="oldPwd" placeholder="" lay-verify="required" lay-verType="tips" class="layui-input">
                                    </div>
                                </div>
                            }
                            <div class="layui-form-item">
                                <label class="layui-form-label">新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" maxlength="18" name="newPwd" placeholder="" lay-verify="required|pass" lay-verType="tips" autocomplete="off" class="layui-input" id="LAY_password">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">确认新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" maxlength="18" name="confrimPwd" placeholder="" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="setmypass">确认修改</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form'], function () {

            var $ = layui.$
                , form = layui.form;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

            form.verify({
                pass: [/^[\S]{6,18}$/, "密码必须6到18位，且不能出现空格"],
                repass: function (t) {
                    if (t !== $("#LAY_password").val()) return "两次密码输入不一致";
                }
            });

            //提交
            form.on('submit(setmypass)', function (data) {
                $.ajax({
                    url: '@Url.Action("secondarypwd", "api")',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data.field),
                    type:'post'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 }, function () {
                        location.reload(true);
                    });
                });
                return false;
            });
        });

    </script>
</body>
</html>
